package com.bookmanger.server.controller;

import com.bookmanger.common.result.Result;
import com.bookmanger.pojo.Entity.BookType;
import com.bookmanger.server.service.BookTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bookType")
@Slf4j
public class BookTypeController {
    
    @Autowired
    private BookTypeService bookTypeService;
    
    /**
     * 查询所有图书分类
     */
    @GetMapping("/findAll")
    public Result findAll() {
        return bookTypeService.findAll();
    }
    
    /**
     * 将图书分类同步到Redis中
     */
    @GetMapping("/syncToRedis")
    public Result syncToRedis() {
        return bookTypeService.syncBookTypesToRedis();
    }
    
    /**
     * 从Redis中获取图书分类
     */
    @GetMapping("/getFromRedis")
    public Result getFromRedis() {
        return bookTypeService.getBookTypesFromRedis();
    }
    
    /**
     * 新增图书分类
     */
    @PostMapping("/add")
    public Result addBookType(@RequestBody BookType bookType) {
        return bookTypeService.addBookType(bookType);
    }
    
    /**
     * 更新图书分类
     */
    @PutMapping("/update")
    public Result updateBookType(@RequestBody BookType bookType) {
        return bookTypeService.updateBookType(bookType);
    }
    
    /**
     * 获取树形结构的图书分类
     */
    @GetMapping("/tree")
    public Result getBookTypeTree() {
        return bookTypeService.getBookTypeTree();
    }
    
    /**
     * 删除图书分类
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteBookType(@PathVariable Integer id) {
        return bookTypeService.deleteBookType(id);
    }
}